//Wed Jun  8 16:31:10 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class PalindromizationDiv2 {
public:
	int getMinimumCost(int);
	bool isP(string);
};

int PalindromizationDiv2::getMinimumCost(int X) {
	for(int i = 0; ; i++){
		stringstream s1;
		stringstream s2;
		s1 << (X+i);
		s2 << (X-i);
		if(isP(s1.str())){
			return i;
		}
		if(X-i >=0 && isP(s2.str())){
			return i;
		}
	}
	return 0;
}

bool PalindromizationDiv2::isP(string s){
	int i, j;
	for(i=0, j=s.size()-1; i<j; i++, j--){
		if(s[i] != s[j])
			return false;
	}
	return true;
}

//Powered by [KawigiEdit] 2.0!
